package com.springboot.repository;

import com.springboot.domain.BtFile;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;
@Repository
public interface FileRepository extends JpaRepository<BtFile,String> {
    @Modifying
    @Query("update BtFile bf set bf.userId = ?1 where bf.id = ?2 ")
    void update(String id, String fileId);

    @Query("select files from BtFile files where files.userId=?1 and (files.parameterName <> 'headPicture' or files.parameterName is null)")
    List<BtFile> findFiles(String userId);

    List<BtFile> findByUserId(String userId);

    @Modifying
    @Query("update BtFile bf set bf.userId = null , bf.effective = ?2 where bf.userId = ?1")
    void unbindFileNew(String id,Integer effective);

    @Query("select id from BtFile bdd where bdd.userId=?1 and bdd.parameterName=?2")
    String findFileId(String userId,String parameterName);

    @Query("select bdd from BtFile bdd where bdd.userId=?1 and bdd.parameterName=?2")
    BtFile findFile(String userId,String parameterName);

}
